(function () {
    'use strict';

    angular.module('app')
        .controller('ScheduleJobFormCtrl', ScheduleJobFormCtrl);

    ScheduleJobFormCtrl.$inject = ['$rootScope', '$scope', '$state','toaster', 'ScheduleJobService'];
    function ScheduleJobFormCtrl($rootScope, $scope,$state, toaster, scheduleJobService) {

        $scope.title = '定时任务信息';
        var id = $state.params.id;
        if (!!id) { //编辑
            $scope.title = '定时任务详情';
            $rootScope.loading = true;
            scheduleJobService.getById(id)
                .then(function (data) {
                    $scope.scheduleJob = data;
                })
                .finally(function () {
                    $rootScope.loading = false;
                });
        } else { //新建
            $scope.title = '新建定时任务';
            $scope.scheduleJob = {

            };
        }

        $scope.saveData = function () {
            $rootScope.loading = true;
            scheduleJobService.saveData($scope.scheduleJob)
                .then(function () {
                    toaster.pop('success', '', '保存成功');
                })
                .finally(function () {
                    $rootScope.loading = false;
                })
            ;
        }

    }
})();